﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BF.IDAL.BaseSystem;
using BF.Infrastructure;
using BF.Model;


namespace BF.SQLServerDAL.BaseSystem
{
    public class Sys_AreaDAL : DALBase<sys_Area, WSJD_BaseFrameworkEntities>, Isys_AreaDAL
    {
        public Sys_AreaDAL(IDatabaseFactory<WSJD_BaseFrameworkEntities> databaseFactory)
            : base(databaseFactory)
        {

        }

        /// <summary>
        /// 根据地区编码取得实体
        /// </summary>
        /// <param name="areaCode"></param>
        /// <returns></returns>
        public sys_Area GetModelByID(string areaCode)
        {
            var query = from p in DataContext.sys_Area
                        where p.sID == areaCode
                        select p;
            return query.FirstOrDefault();
        }

        /// <summary>
        /// 修改实体
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public bool Update(sys_Area model)
        {
            DataContext.ApplyCurrentValues("sys_Area", model);
            return DataContext.SaveChanges() > 0;
        }

        /// <summary>
        /// 跟新集合
        /// </summary>
        /// <param name="list"></param>
        /// <returns></returns>
        public int Update(List<sys_Area> list)
        {
            foreach (sys_Area p in list)
            {
                DataContext.ApplyCurrentValues("sys_Area", p);
            }
            return DataContext.SaveChanges();
        }
    }
}
